<html>
<meta charset="utf-8">
<head>
<script>
var id=0;
problems=[];
function button_oc()
{
	problems.push({problem:ques.value,answer:(document.getElementsByName("ans")[0].checked)?true:false})
	main.innerHTML=generateProblem(problems);
	//if(ans.selected)
	/*
	var f=new FileReader;
	f.readAsText(file.files[0]);
	f.onload=()=>{main.innerHTML=generateProblem(json.parse(decodeURIComponent(f.result)))};*/
}
/*
function doSave(value, type, name) {
    var blob;
    if (typeof window.Blob == "function") {
        blob = new Blob([value], {type: type});
    } else {
        var BlobBuilder = window.BlobBuilder || window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder;
        var bb = new BlobBuilder();
        bb.append(value);
        blob = bb.getBlob(type);
    }
    var URL = window.URL || window.webkitURL;
    var bloburl = URL.createObjectURL(blob);
    var anchor = document.createElement("a");
    if ('download' in anchor) {
        anchor.style.visibility = "hidden";
        anchor.href = bloburl;
        anchor.download = name;
        document.body.appendChild(anchor);
        var evt = document.createEvent("MouseEvents");
        evt.initEvent("click", true, true);
        anchor.dispatchEvent(evt);
        document.body.removeChild(anchor);
    } else if (navigator.msSaveBlob) {
        navigator.msSaveBlob(blob, name);
    } else {
        location.href = bloburl;
    }
}*/
function save(content)
{

var data = new Blob([content],{type:"text/plain"});
var downloadUrl = window.URL.createObjectURL(data);
var anchor = document.createElement("a");
anchor.href = downloadUrl;
anchor.download = "problem.txt";
anchor.click();
window.URL.revokeObjectURL(data); 
}
function daochu_oc()
{	
	save(btoa(encodeURIComponent(JSON.stringify(problems))))
}

function generateProblem(obj)
{
	id=0;
	var html="";
	for(var i in obj)
	{
		html+="<div>";
		html+="<span>"+obj[i].problem+"</span>";
		html+='<label><input type="radio" name="'+id+'" id="'+id+'" value="是">是</label>';
		html+='<label><input type="radio" name="'+id+'" id="'+id+'" value="否">否</label>';
		html+=' 答案：'+((obj[i].answer===true)?"是":"否");
		html+=`<button onclick="problems.splice(${id},1);main.innerHTML=generateProblem(problems)">删除</button>`;
		html+="</div>";
		id++;
	}
	return html;
}
function xianshi_oc()
{
	json.innerHTML=window.location.hostname+window.location.pathname.replace("generate.html","")+"index.html?question="+btoa(encodeURIComponent(JSON.stringify(problems)));
	json.select();
	document.execCommand('copy');
}
</script>
</head>
<body>
<a href="index.html">主页</a>
<div>问题：<textarea id="ques"></textarea><br>答案：<label><input id="ans" type="radio" name="ans" value="是">是</input></label><label><input id="ans" type="radio" name="ans" value="否">否</input></label></div>
<button onclick="button_oc()">增加</button>
<button onclick="daochu_oc()">导出</button>
<button onclick="xianshi_oc()">显示并复制</button>
<div id="main"></div>
<p>数据：</p>
<textarea id="json"></textarea>
</body>
</html>